<!DOCTYPE html>
<html lang="en">

<!-- 
    @author: 带只拖鞋去流浪
    @date: 2021-10-14
    @link: https://www.zhihu.com/people/is666a
    @link: https://space.bilibili.com/391870178
 -->

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>cube-images-show</title>
    <link rel="stylesheet" type="text/css" href="./css/new_file.css"/>
	<SCRIPT src="./js/new_file.js" type=“text/javascript”></SCRIPT>
</head>

<body>
    <div id="app">
        <div class="my-cube">
            <div class="cube cube-1"></div>
            <div class="cube cube-2"></div>
            <div class="cube cube-3"></div>
            <div class="cube cube-4"></div>
            <div class="cube cube-5"></div>
            <div class="cube cube-6"></div>
        </div>
        <div class="selector-cube">
            <div class="cube active-cube"></div>
            <div class="cube"></div>
            <div class="cube"></div>
            <div class="cube"></div>
            <div class="cube"></div>
            <div class="cube"></div>
        </div>
    </div>
    <script>
        const myCube = document.querySelector('.my-cube');
        const myCubes = document.querySelectorAll('.my-cube>.cube');
        const selectorCubes = document.querySelectorAll('.selector-cube>.cube');
        for (let i = 0; i < 6; i++) {
            myCubes[i].style.cssText += `background-image: url(./img/${i+1}.jpg);`;
            selectorCubes[i].style.cssText += `background-image: url(./img/${i+1}.jpg);`;
        }

        selectorCubes.forEach((cube, idx) => {
            cube.addEventListener('click', function () {
                selectorCubes.forEach(ele => {
                    ele.classList.remove('active-cube');
                });
                this.classList.add('active-cube');

                let transformStr = ``;
                switch (idx + 1) {
                    case 1:
                        transformStr = `transform: rotateX(0) rotateY(0) rotateZ(0);`
                        break;
                    case 2:
                        transformStr = `transform: rotateX(0) rotateY(90deg) rotateZ(0);`
                        break;
                    case 3:
                        transformStr = `transform: rotateX(90deg) rotateY(0) rotateZ(0);`
                        break;
                    case 4:
                        transformStr = `transform: rotateX(0) rotateY(-90deg) rotateZ(0);`
                        break;
                    case 5:
                        transformStr = `transform: rotateX(-90deg) rotateY(0) rotateZ(0);`
                        break;
                    case 6:
                        transformStr = `transform: rotateX(-180deg) rotateY(0) rotateZ(0);`
                        break;
                    default:
                        break;
                };

                myCube.style.cssText += transformStr;
            });
        });

        function reSize() {
            let clientWidth = document.documentElement.clientWidth;
            document.documentElement.style.fontSize = clientWidth / 37.5 + 'plbx';
        }

        window.addEventListener('resize', reSize, false);
        reSize();
    </script>
</body>

</html>

